﻿package classes 
{
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.text.TextFormat;
	import flash.text.TextField;
	import flash.display.MovieClip;
	import flash.display.SimpleButton;
	
	public class genericButton extends Sprite
	{
		private var txt:TextField;
		private var tf:TextFormat;
		
		public var isSelected:Boolean;
		private var upClip:MovieClip;
		private var upShape:Shape;
		private var isSelectedShape:Shape;
		
		public function genericButton(_text:String = "", _textSize:uint = 12, _width:Number = 100, _height:Number = 18, _isSelected:Boolean = false) 
		{
		
		var _ellipseWidth:Number = 10;
		var _ellipseHeight:Number = 10;
		
		isSelectedShape = new Shape();
		isSelectedShape.graphics.beginFill( 0x00FF00 );
		isSelectedShape.graphics.drawRoundRect( 0, 0, _width, _height, _ellipseWidth, _ellipseHeight );
		isSelectedShape.graphics.endFill();
			
		upShape = new Shape();
		upShape.graphics.beginFill( 0xFFFFFF );
		upShape.graphics.drawRoundRect( 0, 0, _width, _height, _ellipseWidth, _ellipseHeight);
		upShape.graphics.endFill();
			
		var overShape:Shape = new Shape();
		overShape.graphics.beginFill( 0xCCCCCC );
		overShape.graphics.drawRoundRect( 0, 0, _width, _height, _ellipseWidth, _ellipseHeight);
		overShape.graphics.endFill();
		
		var downShape:Shape = new Shape();
		downShape.graphics.beginFill( 0x666666 );
		downShape.graphics.drawRoundRect( 0, 0, _width, _height, _ellipseWidth, _ellipseHeight );
		downShape.graphics.endFill();
		
		var hitShape:Shape = new Shape();
		hitShape.graphics.beginFill( 0x00FF00 );
		hitShape.graphics.drawRoundRect( 0, 0, _width, _height, _ellipseWidth, _ellipseHeight );
		hitShape.graphics.endFill();
		
		tf = new TextFormat();
		tf.color = 0x000000;
		tf.font = "Verdana";
		tf.size = _textSize;
		tf.align = "center";
		
		txt = new TextField();
		txt.text = _text;
		txt.x = 0;
		txt.y = 0;
		txt.width = upShape.width;
		txt.height = upShape.height;
		txt.selectable = false;
		txt.mouseEnabled = false;
		txt.setTextFormat(tf);
		
		upClip = new MovieClip();
		upClip.addChild(upShape);
			
		var overClip:MovieClip = new MovieClip();
		overClip.addChild(overShape);
		
		var downClip:MovieClip = new MovieClip();
		downClip.addChild(downShape);
			
		//(upState:DisplayObject = null, overState:DisplayObject = null, downState:DisplayObject = null, hitTestState:DisplayObject = null);
		var btn:SimpleButton = new SimpleButton(upClip, overClip, downClip, hitShape);
			
		addChild(btn);
		addChild(txt)
		}	
		
		public function getText():String 
		{
			return this.txt.text;
		}
		
		public function setText(_text:String):void 
		{
			this.txt.text = _text;
			this.txt.setTextFormat(this.tf);
		}
		
		public function setSelected(_isSelected:Boolean):void
		{
			if (_isSelected)
			{
				this.upClip.addChild(isSelectedShape);
				
			}
			else 
			{
				this.upClip.addChild(upShape);
			}
		}
		
	}
}